# -*- coding: utf-8 -*-

from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from config_user import ROLE_ADMIN
from app import db
from app import models
import os.path
#import MySQLdb

db.drop_all()
db.create_all()
try:
    admin = models.Teacher(0,"Administrator","13000000000","735828661@qq.com","jyzdzx2016666","",1,None,ROLE_ADMIN)
    if models.Teacher.query.filter_by(id=admin.id).first() is None:
        db.session.add(admin)
        db.session.commit()
except Exception as e:
    print(str(e))
    pass

if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
    api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO,
                        api.version(SQLALCHEMY_MIGRATE_REPO))
